import axios from 'axios';
import { BASE_URL } from '../src/utils/request.js';
import { customeAppId } from '../src/utils/serviceSwitching.js';

const getConfig = async () => {
  const { data } = await axios.get(
    `${BASE_URL}/merchant/merchant/colorConfig/detail/${customeAppId}`,
  );

  try {
    const str = data.content.colorConfig || '';

    return JSON.parse(str);
  } catch (e) {
    return {};
  }
};

async function getNavBarStyle() {
  const res = await getConfig();
  const { topColor, contentColor } = res
  const isWhite = `${contentColor}`.toLocaleLowerCase() === '#ffffff';
  return {
    // 导航栏背景颜色
    navigationBarBackgroundColor: topColor || '#ffffff',
    // 导航栏标题颜色
    navigationBarTextStyle: isWhite ? 'white' : 'black',
    // 下拉 loading 的样式
    backgroundTextStyle: isWhite ? 'light' : 'dark',
  };
}

export { getConfig, getNavBarStyle };